:- use_module(library(lists)).
:- use_module(library('clp/bounds')).

%increase the Num element of Old list and return a New list

inc(Num,Step,Old,New) :- %write('inc10'),nl,
		var(Step),
		var(New),
		length(Old,Step),
		length(New,Step),
		inc(Num,Step,Old,New).
	%	nth1(Step,New,Tmp2),
	%	not(var(Tmp2)),
	%	write('inc1'),nl.

inc(_,0,_,New) :- not(var(New)),!.
	%	write('inc0'),nl,!.
	%	write(New),nl,!.

inc(Num,Step,Old,New) :- %write('inc2'),write(Step),write(New),nl,
		not(var(New)),
		Num #= Step, 
	%	write('Num = Step'),nl,
		nth1(Step,Old,Tmp),
		Tmp1 #= Tmp + 1,
		nth1(Step,New,Tmp1),
		Step1 #= Step - 1,
		inc(Num,Step1,Old,New),
		nth1(Step,New,Tmp2),
		not(var(Tmp2)).
	%	write('inc3'),nl.
		
inc(Num,Step,Old,New) :- %write('inc3'),write(Step),write(New),nl,
		not(var(New)),
		Num #\= Step, 
	%	write('Num != Step'),nl,
		nth1(Step,Old,Tmp),
		nth1(Step,New,Tmp),
		Step1 #= Step - 1,
		inc(Num,Step1,Old,New),
		nth1(Step,New,Tmp2),
		not(var(Tmp2)).
	%	write('inc4'),nl.


:- begin_tests(inc_arr_tests).

%:- consult(inc_arr).

test(inc) :-
	inc(2,S,[1,2,3], New),
	S = 3,
	New = [1,3,3].

test(inc) :-
        	inc(3,S,[0,0,0,0,0], New),
	S = 5,
	New = [0,0,1,0,0].

:- end_tests(inc_arr_tests).

%show_coverage(run_tests).























